import 'package:bruno/bruno.dart';
import 'package:common/service/log_service.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import '../../../theme/font.dart';
import 'report_logic.dart';
import 'report_state.dart';

/// @description:
/// @author
/// @date: 2024-09-23 16:13:32
class ReportPage extends StatelessWidget {
  final ReportLogic logic = Get.put(ReportLogic());
  final ReportState state = Get.find<ReportLogic>().state;

  ReportPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: BrnAppBar(title: '举报'),
      backgroundColor: Colors.white,
      body: GetBuilder<ReportLogic>(
          init: ReportLogic(),
          initState: (_) {},
          builder: (context) {
            return CustomScrollView(
              slivers: [
                SliverToBoxAdapter(child: buildContentImageWerppar()),
                SliverToBoxAdapter(
                    child: Container(
                  width: double.infinity,
                  padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 10),
                  margin: const EdgeInsets.only(top: 30),
                  child: GestureDetector(
                    onTap: () {
                      logic.doPostFeekBack();
                    },
                    child: Container(
                      height: 42.h,
                      alignment: Alignment.center,
                      padding: const EdgeInsets.symmetric(horizontal: 15),
                      margin: const EdgeInsets.symmetric(horizontal: 5),
                      decoration: BoxDecoration(
                        borderRadius: BorderRadius.all(Radius.circular(21.r)),
                        color: const Color(0xFF25D4D0),
                      ),
                      child: Text('确认提交',
                          style: TextStyle(color: Colors.white, fontSize: 15.sp, fontWeight: AppFontWeight.medium)),
                    ),
                  ),
                )),
              ],
            );
          }),
    );
  }

  Container buildContentImageWerppar() {
    return Container(
      padding: const EdgeInsets.only(left: 14, right: 14, bottom: 10),
      decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(8)),
      child: Column(
        children: [
          Container(
              color: Colors.white,
              padding: const EdgeInsets.symmetric(vertical: 10),
              alignment: Alignment.centerLeft,
              child: Text('请选择举报原因',
                  style: TextStyle(fontSize: 14.sp, color: const Color(0xFF000000), fontWeight: AppFontWeight.medium))),
          Container(
            // padding: EdgeInsets.only(bottom: 13.h),
            padding: EdgeInsets.only(left: 15.w, right: 15.w),
            decoration:
                BoxDecoration(color: const Color(0xFFF4F6F6), borderRadius: BorderRadius.all(Radius.circular(6.r))),
            child: SizedBox(
              child: ConstrainedBox(
                constraints: BoxConstraints(minHeight: 48.h),
                child: TextField(
                  maxLength: 11,
                  focusNode: state.phoneFocusNode,
                  controller: state.controller,
                  obscureText: false,
                  cursorWidth: 2,
                  cursorColor: const Color(0xFF2CC0B1),
                  // cursorHeight: 18.h,
                  autofocus: false, // 指不自动获取焦点
                  onChanged: (value) {
                    state.phone = value;
                  },
                  keyboardType: TextInputType.phone,
                  inputFormatters: [
                    FilteringTextInputFormatter.allow(RegExp(r'[0-9]')) //设置只允许输入数字
                  ],
                  style: TextStyle(color: const Color(0xFF0C1B19), fontSize: 14.sp, fontWeight: AppFontWeight.regular),
                  decoration: InputDecoration(
                      hintText: '请填写手机号码，方便我们与你联系哦~',
                      counterText: '',
                      hintStyle: TextStyle(color: const Color(0xFFC2C6CC), fontSize: 14.sp),
                      border: InputBorder.none),
                ),
              ),
            ),
          ),
          Container(
              padding: const EdgeInsets.only(top: 16, bottom: 10),
              alignment: Alignment.centerLeft,
              child: Text('为帮助审核人员尽快处理，请补充详细举报说',
                  style: TextStyle(fontSize: 14.sp, color: const Color(0xFF000000), fontWeight: AppFontWeight.medium))),
          Container(
            // width: 345.w,
            height: 150.h,
            padding: EdgeInsets.only(left: 15.w, right: 15.w, bottom: 10),
            decoration:
                BoxDecoration(color: const Color(0xFFF6F6F6), borderRadius: BorderRadius.all(Radius.circular(8.r))),
            child: TextField(
              maxLength: 100,
              focusNode: state.focusNode,
              textInputAction: TextInputAction.done,
              style: TextStyle(color: const Color(0xFF263B38), fontSize: 13.sp, height: 1.5),
              maxLines: 12,
              // controller: _publishState.textController,
              decoration: InputDecoration(
                hintText: '描述对方行为',
                hintStyle:
                    TextStyle(color: const Color(0xFF999999), fontSize: 13.sp, fontWeight: AppFontWeight.regular),
                hintMaxLines: 3,
                border: InputBorder.none,
                // counterText: '${_publishState.textController.text.length} / 500'
                // isCollapsed: true,
              ),
              // cursorColor: normalBlackColor,
              onChanged: (value) {
                logs(value);
                debugPrint('onChanged--');
                if (value.characters.length >= state.minInputCount) {
                  state.isCanPublish = true;
                } else {
                  state.isCanPublish = false;
                }
                logic.update();
                state.content = value;
                // setState(() {});
                // _publishState.textController.text;
              },
              onEditingComplete: () {
                state.focusNode.unfocus();
              },
            ),
          ),
          Container(
              color: Colors.white,
              padding: const EdgeInsets.only(top: 16, bottom: 8),
              alignment: Alignment.centerLeft,
              child: Row(children: [
                Text('上传图片',
                    style:
                        TextStyle(fontSize: 14.sp, color: const Color(0xFF000000), fontWeight: AppFontWeight.medium)),
                Text('(最多3张）',
                    style: TextStyle(fontSize: 14.sp, color: const Color(0xFF000000), fontWeight: AppFontWeight.medium))
              ])),
          // AssetPickerWidget(
          //   maxAssets: 3,
          //   callBack: (assetEntityList) async {
          //     List<String> filePaths = [];
          //     for (var assetEntity in assetEntityList) {
          //       File? file = await assetEntity.originFile;
          //       filePaths.add(file!.path);
          //     }
          //     state.filePaths = filePaths;
          //   },
          // ),
          Container(
              padding: const EdgeInsets.only(top: 16, bottom: 10),
              alignment: Alignment.centerLeft,
              child: Text('我们会在12h内尽快处理您的举报，并根据违规情况进行处罚，请您认真对待。',
                  style: TextStyle(fontSize: 12.sp, color: const Color(0xFF999999)))),
        ],
      ),
    );
  }
}
